package com.lagou.edu.transformation;

import org.apache.flink.streaming.api.functions.source.SourceFunction;

public class MySource implements SourceFunction<Long> {

    private long count = 1;
    private boolean isRunning = true;

    /**
     * 自定义数据源  返回一个数据，源源不断的产生数据
     * @param ctx 发送数据的实体
     * @throws Exception
     */
    public void run(SourceContext<Long> ctx) throws Exception {
        while(isRunning) {
            ctx.collect(count);
            count ++;
            Thread.sleep(1000);
        }
    }

    /**
     * 停掉的操作有哪些
     */
    public void cancel() {
        isRunning = false;
    }
}
